package com.ruoyi.match.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.match.domain.vo.UserInfoVo;
import com.ruoyi.match.service.UserInfoService;
import com.ruoyi.match.service.UserTagService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Security;

@RestController
@RequestMapping("/match/userInfo")
public class UserInfoController extends BaseController {

    @Autowired
    private UserInfoService userInfoService;



    @Autowired
    private UserTagService userTagService;

    //查询用户信息
    @GetMapping("/getUserInfo/{userName}")
    public AjaxResult getUserInfo(@PathVariable("userName") String userName){

        Long userId = userInfoService.selectUserId(userName);
        System.out.println("ID:" + userId);

        UserInfoVo userInfoVo = userInfoService.selectUserInfo(userId);


        System.out.println("用户信息" + userInfoVo);
        return AjaxResult.success(userInfoVo);

    }


    //查询当前用户信息
    @GetMapping("/getMyInfo")
    public AjaxResult showMyInfo(){

        Long userId = SecurityUtils.getUserId();

        UserInfoVo userInfoVo = userInfoService.selectUserInfo(userId);


        return AjaxResult.success(userInfoVo);

    }

    //修改当前用户个人信息
    @PutMapping("/updateUserInfo")
    public AjaxResult updateUserInfo(@RequestBody UserInfoVo userInfoVo){

        Long userId = SecurityUtils.getUserId();
        userInfoVo.setUserId(userId);
        if(userInfoService.checkNickNameUnique(userInfoVo.getNickName(), userId) != 0){
            return AjaxResult.error("昵称已存在");
        }else if(userInfoService.checkPhoneUnique(userInfoVo.getPhoneNumber(), userId) != 0){
            return AjaxResult.error("手机号已存在");
        }else if(userInfoService.checkEmailUnique(userInfoVo.getEmail(), userId) != 0){
            return AjaxResult.error("邮箱已存在");
        }

        userInfoService.updateUserInfo(userInfoVo);

        return AjaxResult.success("修改成功！");

    }





}
